package com.chengzzz.czsee.adapter

import android.content.Intent
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import com.chengzzz.czsee.R
import com.chengzzz.czsee.core.PlayActivity
import com.chengzzz.czsee.core.infoActivity

class playAdapter(val list: List<String>,val name: String) : RecyclerView.Adapter<playAdapter.ViewHolder>() {
    companion object {
//       val counts: List<String> = list.split("$");
    }

    inner class ViewHolder(view: View):RecyclerView.ViewHolder(view){
        val name:TextView =view.findViewById(R.id.count)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.playrecycle, parent,false)
        val viewHolder = ViewHolder(view)
        viewHolder.itemView.setOnClickListener {

            val url: String = list[viewHolder.adapterPosition].split("$").get(1)
//            Log.d("TAG", "onCreateViewHolder: "+url)
//            Toast.makeText(parent.context, url, Toast.LENGTH_SHORT).show()
            var intent = Intent(it.context, PlayActivity::class.java)
            intent.putExtra("url",url)
            intent.putExtra("name",name)
            it.context.startActivity(intent)
        }
        return viewHolder
    }

    override fun getItemCount(): Int = list.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.name.text = list[position].split("$").get(0)


        Log.d("TAG", "onCreateViewHolder: "+list[position].split("$").get(0))
    }

}